//Accepted
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;


typedef struct pppp{
	int x, y, z;
} ponto;

queue<ponto> q;


int d[8][2] = {{1,-1},{-1,-1},{1,1},{-1,1},{1,-1},{-1,-1},{1,1},{-1,1}};
int n, m, n1, m1, i, j, s[30][30];
ponto a, b, c;
bool ok[30][30];

int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	memset(ok,1,sizeof(ok));
	scanf("%d%d%d%d", &n, &m, &n1, &m1);
	for(i=0;i<n;++i)
	for(j=0;j<m;++j){
		scanf("%d", &s[i][j]);
		if(s[i][j]==3){
			a.x=i;a.y=j;
		}
		else if(s[i][j]==4){
			b.x=i;b.y=j;
		}
	}
	for(i=0;i<4;++i){
		d[i][0]*=n1;
		d[i][1]*=m1;
	}
	for(;i<8;++i){
		d[i][1]*=n1;
		d[i][0]*=m1;
	}
	a.z=0;
	c.z=0;
	q.push(a);
	while(!q.empty()){
		a=q.front();q.pop();
		if(a.x==b.x&&a.y==b.y)break;
		for(i=0;i<8;++i){
			c.x=d[i][0]+a.x;
			c.y=d[i][1]+a.y;
			c.z=a.z+1;
			if((0<=c.x&&c.x<n)&&(0<=c.y&&c.y<m)){
				if(ok[c.x][c.y]&&(s[c.x][c.y]==1||s[c.x][c.y]==4)){
					ok[c.x][c.y]=0;
					q.push(c);
				}
			}
		}
	}
	printf("%d\n", a.z);
	
	return 0;
}
